function [YearConvexity, PerConvexity] = bndconvp(Price, ...
                                    CouponRate, Settle, Maturity, varargin)
%BNDCONVP Convexity of Bond Given Price.
%   BNDCONVP calculates the convexity of NUMBONDS fixed income securities
%   given a clean price for each bond. This function will determine the
%   convexity for a bond regardless of whether the bond's coupon structure
%   contains short or long first or last coupon periods (i.e. regardless of
%   whether the coupon structure is synched to maturity). This function will
%   also determine the convexity of a zero coupon bond.
%
%   [YearConvexity, PerConvexity] = bndconvp(Price, CouponRate, Settle, ...
%          Maturity)
%
%   [YearConvexity, PerConvexity] = bndconvp(Price, CouponRate, Settle, ...
%          Maturity, Period, Basis, EndMonthRule, IssueDate, FirstCouponDate, ...
%          LastCouponDate, StartDate, Face)
%
%   [YearConvexity, PerConvexity] = bndconvp(Price, CouponRate, ...
%          Settle, Maturity,'Param1','Value1',...)
%
%   Optional Inputs: Period, Basis, EndMonthRule, IssueDate, FirstCouponDate,
%                    LastCouponDate, StartDate, Face, LastCouponInterest,
%                    CompoundingFrequency, DiscountBasis
%
%   Note:
%   - All non-scalar or empty matrix input arguments must be either NUMBONDSx1
%     or 1xNUMBONDS conforming vectors.
%   - Fill unspecified entries in input vectors with NaN.
%   - Dates can be serial date numbers or date strings.
%   - Optional inputs can be specified as parameter value pairs.  If
%     LastCouponInterest, CompoundingFrequency or DiscountBasis are input,
%     optional inputs must be specified as parameter value pairs.
%     Otherwise, optional inputs may be specified by order according to the
%     help.
%
%   Inputs:
%        Price - Clean price.
%
%   CouponRate - Coupon rate in decimal form.
%
%       Settle - Settlement date.
%
%     Maturity - Maturity date.
%
%   Optional Inputs:
%            Period - Number of coupons payments per year.
%                     Possible values include:
%                     0, 1, 2 (default), 3, 4, 6, 12
%
%
%             Basis - Day-count basis.
%                     Possible values include:
%                     0 - actual/actual (default)
%                     1 - 30/360 SIA
%                     2 - actual/360
%                     3 - actual/365
%                     4 - 30/360 PSA
%                     5 - 30/360 ISDA
%                     6 - 30/360 European
%                     7 - actual/365 Japanese
%                     8 - actual/actual ISMA
%                     9 - actual/360 ISMA
%                    10 - actual/365 ISMA
%                    11 - 30/360 ISMA
%                    12 - actual/365 ISDA
%                    13 - bus/252
%
%      EndMonthRule - End-of-month rule; default is 1 (in effect)
%                     0 - Rule is NOT in effect for the bond(s)
%                     1 - (default) Rule is in effect for the bond(s) (meaning
%                         that a security that pays coupon interest on the last
%                         day of the month will always make payment on the last
%                         day of the month)
%
%         IssueDate - Bond issue date.
%
%   FirstCouponDate - Irregular or normal first coupon date.
%
%    LastCouponDate - Irregular or normal last coupon date.
%
%         StartDate - Forward starting date of payments.
%
%              Face - Face value of the bond; default is 100.
%
%   Outputs:
%   YearConvexity - [NUMBONDSx1 vector] of the yearly convexity.
%
%    PerConvexity - [NUMBONDSx1 vector] of the periodic convexity.
%
%   See also BNDCONVY, BNDDURP, BNDDURY.

%   Copyright 1995-2009 The MathWorks, Inc.
%   $Revision: 1.8.2.12 $   $Date: 2009/11/05 16:58:56 $

% Checking input arguments
if (nargin < 4)
   error('Finance:bndconvp:tooFewinputs', 'Too few inputs.');
end

try
    Yield = bndyield(Price, CouponRate, Settle, Maturity, varargin{:});
catch ME
    throwAsCaller(ME)
end

try
    [YearConvexity, PerConvexity] = bndconvy(Yield, CouponRate,...
        Settle, Maturity, varargin{:});
catch ME
    throwAsCaller(ME)
end